<template>
  <div
    class="header-wrapper"
    :style="{
      height: height,
      backgroundColor: backgroundColor,
      color: textColor
    }">
    <div class="l">{{ title }}</div>
    <div class="c">{{ pageName }}</div>
    <div class="r" v-show="isHasHandle">
      <el-dropdown trigger="click" @command="emit('handleCommand', $event)">
        <span class="el-dropdown-link">
          <el-avatar
            :size="30"
            src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png" />
          <span>{{ username }}</span>
          <el-icon class="el-icon--right">
            <arrow-down />
          </el-icon>
        </span>

        <template #dropdown>
          <slot name="dropdownMenu"></slot>
          <el-dropdown-menu>
            <el-dropdown-item command="logOut">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { ArrowDown } from '@element-plus/icons-vue'
  import type { IBasicProps } from './types/header'

  withDefaults(defineProps<IBasicProps>(), {
    height: '60px',
    backgroundColor: '#001529',
    textColor: '#fff',

    title: '',
    pageName: '示例页面名称',
    username: '示例用户',

    isHasHandle: true
  })

  const emit = defineEmits<{
    handleCommand: [command: string | number | object] // 具名元组语法
  }>()
</script>

<style scoped lang="scss">
  .header-wrapper {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    box-sizing: border-box;
    .l {
      display: flex;
      align-items: center;
      font-weight: 600;
      font-size: 20px;
    }
    .c {
      font-size: 16px;
      font-weight: 600;
    }
    .r {
      display: flex;
      align-items: center;
      .name {
        margin-left: 8px;
      }
      .el-dropdown-link {
        cursor: pointer;
        display: flex;
        align-items: center;
        color: #fff;
        gap: 8px;
      }
    }
  }
</style>
